void httpPut(clientRequestTask *t)
{
    httpStatus(t, 200, "OK");
    httpHeader(t, "Content-Type", "text/html");
    httpHeader(t, "Connection", "close");
    httpBody(t, "\r\n");

    sprintf(t->path, "%s%s", t->xp->path, t->uri);

    mode_t mode;
    struct stat st;
    int i, len = strlen(t->path);
    int flag = 0;
    for (i = 0; i < len; i++) {
        if (t->path[i] == '/') {
            t->path[i] = '\0';
            if (access(t->path, F_OK) == 0) {
                stat(t->path, &st);
                if ((st.st_mode & S_IFMT) != S_IFDIR) {
                    sprintf(t->line, "3001, Path '%s' already exists, and is not a directory!", t->path);
                    httpBody(t, t->line);
                    flag = 1;
                    break;
                }
                mode = st.st_mode & 0777;
            }
            else {
                mkdir(t->path, mode);
            }
            t->path[i] = '/';
        }
    }
    
    if (!flag) {
        int isFile = 0;
        if (t->path[len - 1] != '/') {
            if (stat(t->path, &st) == -1) {
                isFile = 1;
            }
            else if ((st.st_mode & S_IFMT) == S_IFREG) {
                isFile = 1;
            }
        }
        if (isFile) {
            int n = 0;
            if (t->contentLength > 0)
                n = saveFile(t);
            if (n < 0)
                sprintf(t->line, "3003, Put file '%s' failed!", t->path);
            else 
                sprintf(t->line, "3000, Put file '%s' successfully, %d bytes written!", t->path, n);
            httpBody(t, t->line);
        }
        else {
            sprintf(t->line, "3002, '%s' is a directory!", t->path);
            httpBody(t, t->line);
        }
    }
}
